#include "stdafx.h"

#include "file.h"
#include <fstream>
#include <lean/logging/errors.h>

namespace funpl
{

namespace util
{

// Gets the contents of the given file.
std::string file_contents(const char *path)
{
	std::string contents;

	std::ifstream file(path, std::ifstream::in);

	if (!file.is_open())
		LEAN_THROW_ERROR_CTX("Could not open file", path);

	file.seekg(0, std::ifstream::end);
	size_t fileSize = static_cast<size_t>( file.tellg() );
	file.seekg(0, std::ifstream::beg);

	contents.resize(fileSize);
	file.read(&contents[0], fileSize);

	return contents;
}

} // namespace

} // namespace